-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use case insentive comparison to get sheet name #3791
Conversation
Please add |
Thank you for the feedback, it's done! |
I have found a situation which your change does not cover. I need to think about it a little more. $spreadsheet = new Spreadsheet();
$sheet1 = $spreadsheet->getActiveSheet();
$sheet1->setTitle('firstsheet');
$sheet2 = $spreadsheet->createSheet();
$sheet2->setTitle('Firstsheet', true, false); If the third parameter to setTitle is true (default), PhpSpreadsheet will append a number to the sheet name until it finds a unique name. However, if it is false, it won't do that, and so this code will create a corrupt spreadsheet. I do not understand the use case for that third parameter. In the test suite, it is used only in WorksheetTest; I would be surprised if it was ever used "in the wild", and I imagine "caveat emptor" should apply to anyone who uses it. So, I don't think you should do anything about it. But, the first statement in Worksheet::setTitle: // Is this a 'rename' or not?
if ($this->getTitle() == $title) {
return $this;
} For consistency with your change, that should probably be a case-insensitive compare as well. Can you make that change and add an appropriate test in WorksheetTest::testSetTitleDuplicate? |
No, it turns out that Excel allows you to change the sheet name in this manner (and adjusts defined names etc. accordingly). So the change I suggested to setTitle should not be made after all. Sorry if you wasted any time on it. |
Thank you for your contribution. |
Thank you for your work! |
This is:
Checklist:
Why this change is needed?
For now, the method which check if a sheetname already exists, uses a case-sensitive comparison which can cause issue as Excel doesn't allow to have 2 sheets with the same name and uses a case-insensitive comparison. So, I propose to respect the same rule.